package com.groupThree.service;

import com.groupThree.bean.Courier;
import com.groupThree.bean.StateOfAU;
import com.groupThree.dao.BaseCourierDao;
import com.groupThree.dao.imp.CourierDaoMysql;

import java.util.List;
import java.util.Map;

public class CourierService {

    private static BaseCourierDao dao = new CourierDaoMysql();

    public static List<Map<String, Integer>> console() {
        return dao.console();
    }

    public static List<Courier> findAll(boolean limit, int offset, int pageNumber) {
        return dao.findAll(limit, offset, pageNumber);
    }


    public static Courier findByC_Phone(String c_phone) {
        return dao.findByC_Phone(c_phone);
    }


    public static StateOfAU insert(Courier c) {
        StateOfAU state = new StateOfAU();
        //录入失败
        if (dao.findSameC_Phone(c.getC_phone())) {
            System.out.println("该手机号码已经被注册!");
            state.setStateAu(1);
            return state;
        }
        if (dao.findSameC_IDcard(c.getC_idcard()) ) {
            System.out.println("该身份证号码已经存在！");
            state.setStateAu(2);
            return state;
        }
            //录入成功
            dao.insert(c);
            state.setStateAu(0);
            return state;



    }


    public static StateOfAU update(int c_id, Courier newCourier) {
        StateOfAU state = new StateOfAU();
        if (newCourier.getC_phone() != null && newCourier.getC_idcard() != null) {
            dao.delete(c_id);
            return insert(newCourier);

        } else {
            state.setStateAu(-1);
            return state;
        }


    }

    public static boolean deleteByC_ID(int c_id){
        return dao.delete(c_id);
    }

    public static boolean delete(String c_phone) {
        return dao.delete(c_phone);
    }

    public static boolean updateLoginTime(String c_phone){
        return dao.updateLoginTime(c_phone);
    }

    public static boolean updateDeliveries(String c_phone){
        return dao.updateDeliveries(c_phone);
    }
}
